package com.marshall.scstudy.controller;

import com.marshall.scstudy.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by
 *
 * @author : Marshall
 * @datetime: 2021/11/4 14:42
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentinfook(@PathVariable("id") Integer id){
        String paymentinfook = paymentService.paymentinfook(id);
        log.info("res : {}",paymentinfook);
        return paymentinfook;
    }

    @GetMapping("/payment/hystrix/out/{id}")
    public String paymentinfoout(@PathVariable("id") Integer id){
        String res = paymentService.paymentinfoout(id);
        log.info("res : {}",res);
        return res;
    }
    // 下面是全局fallback方法
    public String payment_Global_FallbackMethod()
    {
        return "Global异常处理信息，请稍后再试，/(ㄒoㄒ)/~~";
    }


    @GetMapping("/payment/hystrix/curcuitBreaker/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        String res = paymentService.paymentCircuitBreaker(id);
        log.info("res : {}",res);
        return res;
    }

}
